package com.example.ass7.helper;

/**
 * @author Meirav Ben Izhak
 */
public class Convertor {

    /**
     * @param numberString
     *            a String containing the int representation to be parsed.
     * @return The integer value represented by the argument in decimal if the
     *         string contain a parsable integer; Otherwise, return null.
     */
    public static int parseInt(String numberString) {
        int intNumber = 0;
        if (null != numberString) {
            try {
                intNumber = Integer.parseInt(numberString);
            } catch (NumberFormatException numberFormatException) {
                intNumber = 0; // Default if can't parse to int.
            }
        }
        return intNumber;
    }

    /**
     * @param numberString
     *            numberString
     * @return double
     */
    public static double parseDouble(String numberString) {
        double doubleNumber = 0.0;
        if (null != numberString) {
            try {
                doubleNumber = Double.parseDouble(numberString);
            } catch (NumberFormatException numberFormatException) {
                doubleNumber = 0.0; // Default if can't parse to double.
            }
        }
        return doubleNumber;
    }

}
